#include <iostream>
#include <string.h>
#include "utilities.h"

using namespace std;

void reverseString(char *in_string) {
	if (in_string == NULL) {
		return;
	}

	int len = strlen(in_string);
	char *start = in_string;
	char *end = in_string + len - 1;

	while(start < end) {
		char tmp = *start;
		*start++ = *end;
		*end-- = tmp;
	}

	return;
}

void removeDuplicate(char *in_string) {
	bool hit[256];
	memset(hit, 0, sizeof(bool) * 256);
	
	size_t len = strlen(in_string);
	size_t i;

	size_t loc = 0;
	for (i = 0; i < len; i++) {
		if (hit[in_string[i]] == false) {
			hit[in_string[i]] = true;
			in_string[loc++] = in_string[i];
		}
	}
	
	in_string[loc] = '\0';

	return;		
}

void removeDuplicateN2(char *in_string) {
	if (in_string == NULL) {
		return;
	}

	size_t len = strlen(in_string);
	size_t i, j, tail;
	tail = 1;
	for (i = 1; i < len; i++) {
		for (j = 0; j < tail; j++) {
			if (in_string[j] == in_string[i]) {
				break;
			}
		}

		if (j == tail) {
			in_string[tail] = in_string[i];
			++tail;
		}
	}

	in_string[tail] = '\0';

	return;
}

